Imports System.Text
Imports System.Configuration

Public Class frmGLTransAdd
    Inherits System.Windows.Forms.Form
    Dim GrossTotal As Decimal
    Dim GridRows As Integer
    Dim SavedID As Integer
    Dim RowUpdate As Boolean

    'Dim ArAccount As String =ConfigurationManager.AppSettings("GLReceivableControlAccount")
    'Dim ApAccount As String =ConfigurationManager.AppSettings("GLPayableControlAccount")
    'Dim IcAccount As String =ConfigurationManager.AppSettings("GLInventoryControlAccount")
    'Dim FaAccount As String =ConfigurationManager.AppSettings("GLAssetControlAccount")

    Dim AR_Rec_AC As String = ConfigurationManager.AppSettings("AR_Rec_AC")
    Dim AP_Pay_AC As String = ConfigurationManager.AppSettings("AP_Pay_AC")
    Dim IC_Cont_AC As String = ConfigurationManager.AppSettings("IC_Cont_AC")
    Dim EMP_Cont_AC As String = ConfigurationManager.AppSettings("EMP_Cont_AC")

    Dim ArAc As Boolean = False
    Dim ApAc As Boolean = False
    Dim FaAc As Boolean = False
    Dim EMAc As Boolean = False

    Dim DrTotal As Decimal = 0
    Dim CrTotal As Decimal = 0
    Dim DebitOrCredit As Integer = 1
    Dim GlArAdd As frmGLARTransAdd
    Dim GlApAdd As frmGLAPTransAdd
    Dim icoSearch As frmGLJournalSearch
    Dim icoPost As frmGLJournalPost
    Dim ArAccount1 As String = "1100"
    Dim ArAccount2 As String = "1101"
    Dim ArAccount3 As String = "1102"
    Dim ArAccount4 As String = "1103"
    Dim ApAccount As String = "1900"
    Dim IcAccount1 As String = "1310"
    Dim IcAccount2 As String = "1320"
    Dim IcAccount3 As String = "1330"
    Dim IcAccount4 As String = "1340"
    Dim IcAccount5 As String = "1360"
    Dim FaAccount As String = ""
    Friend WithEvents voucher_txt As System.Windows.Forms.TextBox
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents Label12 As System.Windows.Forms.Label
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmbChart As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdPost As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdPrint As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdSave As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdDelete As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdCut As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdOpen As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdNew As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmbDoc As DevComponents.DotNetBar.Controls.ComboBoxEx
    Dim invoiceDS As DataSet = New DataSet("Invoice")

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents tbDate As System.Windows.Forms.DateTimePicker
    Friend WithEvents tbDesc As System.Windows.Forms.TextBox
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents tbCredit As System.Windows.Forms.TextBox
    Friend WithEvents tbDpt As System.Windows.Forms.TextBox
    Friend WithEvents tbDebit As System.Windows.Forms.TextBox
    Friend WithEvents tbDetail As System.Windows.Forms.TextBox
    Friend WithEvents tbNum As System.Windows.Forms.TextBox
    Friend WithEvents tbCrTotal As System.Windows.Forms.TextBox
    Friend WithEvents tbDrTotal As System.Windows.Forms.TextBox
    Friend WithEvents tbRefer As System.Windows.Forms.TextBox
    Friend WithEvents tbTrxNo As System.Windows.Forms.TextBox
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents tbTrx2 As System.Windows.Forms.TextBox
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents tbDiff As System.Windows.Forms.TextBox
    Friend WithEvents gLtransactionEditList1 As GLtransactionEditList
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmGLTransAdd))
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.tbRefer = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid()
        Me.tbDate = New System.Windows.Forms.DateTimePicker()
        Me.tbCredit = New System.Windows.Forms.TextBox()
        Me.tbDpt = New System.Windows.Forms.TextBox()
        Me.tbDebit = New System.Windows.Forms.TextBox()
        Me.tbDetail = New System.Windows.Forms.TextBox()
        Me.tbDesc = New System.Windows.Forms.TextBox()
        Me.tbNum = New System.Windows.Forms.TextBox()
        Me.tbCrTotal = New System.Windows.Forms.TextBox()
        Me.tbDrTotal = New System.Windows.Forms.TextBox()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.tbTrxNo = New System.Windows.Forms.TextBox()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.tbTrx2 = New System.Windows.Forms.TextBox()
        Me.Label10 = New System.Windows.Forms.Label()
        Me.tbDiff = New System.Windows.Forms.TextBox()
        Me.gLtransactionEditList1 = New GLtransactionEditList()
        Me.voucher_txt = New System.Windows.Forms.TextBox()
        Me.Label11 = New System.Windows.Forms.Label()
        Me.Label12 = New System.Windows.Forms.Label()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.cmdPost = New DevComponents.DotNetBar.ButtonX()
        Me.cmdPrint = New DevComponents.DotNetBar.ButtonX()
        Me.cmdSave = New DevComponents.DotNetBar.ButtonX()
        Me.cmdDelete = New DevComponents.DotNetBar.ButtonX()
        Me.cmdCut = New DevComponents.DotNetBar.ButtonX()
        Me.cmdOpen = New DevComponents.DotNetBar.ButtonX()
        Me.cmdNew = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.cmbChart = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.cmbDoc = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label1.Location = New System.Drawing.Point(154, 15)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(37, 18)
        Me.Label1.TabIndex = 84
        Me.Label1.Text = "Date"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label2.Location = New System.Drawing.Point(513, 18)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(52, 18)
        Me.Label2.TabIndex = 86
        Me.Label2.Text = "Refer #"
        '
        'tbRefer
        '
        Me.tbRefer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbRefer.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbRefer.Location = New System.Drawing.Point(516, 63)
        Me.tbRefer.MaxLength = 10
        Me.tbRefer.Name = "tbRefer"
        Me.tbRefer.Size = New System.Drawing.Size(136, 26)
        Me.tbRefer.TabIndex = 1
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(7, 85)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(83, 18)
        Me.Label3.TabIndex = 94
        Me.Label3.Text = "Account No."
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label4.Location = New System.Drawing.Point(104, 85)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(98, 18)
        Me.Label4.TabIndex = 95
        Me.Label4.Text = "Account Name"
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label5.Location = New System.Drawing.Point(358, 85)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(78, 18)
        Me.Label5.TabIndex = 96
        Me.Label5.Text = "Description"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.BackColor = System.Drawing.Color.Transparent
        Me.Label6.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label6.Location = New System.Drawing.Point(797, 85)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(71, 18)
        Me.Label6.TabIndex = 97
        Me.Label6.Text = "Debit Amt"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.BackColor = System.Drawing.Color.Transparent
        Me.Label7.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label7.Location = New System.Drawing.Point(889, 85)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(75, 18)
        Me.Label7.TabIndex = 98
        Me.Label7.Text = "Credit Amt"
        Me.Label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'DataGrid1
        '
        Me.DataGrid1.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.DataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.DataGrid1.CaptionVisible = False
        Me.DataGrid1.ColumnHeadersVisible = False
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.FlatMode = True
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(7, 159)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.ParentRowsVisible = False
        Me.DataGrid1.ReadOnly = True
        Me.DataGrid1.RowHeadersVisible = False
        Me.DataGrid1.RowHeaderWidth = 0
        Me.DataGrid1.Size = New System.Drawing.Size(964, 226)
        Me.DataGrid1.TabIndex = 180
        Me.DataGrid1.TabStop = False
        '
        'tbDate
        '
        Me.tbDate.Format = System.Windows.Forms.DateTimePickerFormat.[Short]
        Me.tbDate.Location = New System.Drawing.Point(158, 61)
        Me.tbDate.Name = "tbDate"
        Me.tbDate.Size = New System.Drawing.Size(108, 26)
        Me.tbDate.TabIndex = 4
        Me.tbDate.TabStop = False
        '
        'tbCredit
        '
        Me.tbCredit.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbCredit.Location = New System.Drawing.Point(876, 131)
        Me.tbCredit.MaxLength = 12
        Me.tbCredit.Name = "tbCredit"
        Me.tbCredit.Size = New System.Drawing.Size(95, 26)
        Me.tbCredit.TabIndex = 7
        Me.tbCredit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'tbDpt
        '
        Me.tbDpt.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbDpt.Location = New System.Drawing.Point(68, 131)
        Me.tbDpt.MaxLength = 3
        Me.tbDpt.Name = "tbDpt"
        Me.tbDpt.Size = New System.Drawing.Size(37, 26)
        Me.tbDpt.TabIndex = 185
        Me.tbDpt.TabStop = False
        '
        'tbDebit
        '
        Me.tbDebit.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbDebit.Location = New System.Drawing.Point(778, 131)
        Me.tbDebit.MaxLength = 12
        Me.tbDebit.Name = "tbDebit"
        Me.tbDebit.Size = New System.Drawing.Size(96, 26)
        Me.tbDebit.TabIndex = 6
        Me.tbDebit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'tbDetail
        '
        Me.tbDetail.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbDetail.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.tbDetail.Location = New System.Drawing.Point(361, 131)
        Me.tbDetail.MaxLength = 50
        Me.tbDetail.Name = "tbDetail"
        Me.tbDetail.Size = New System.Drawing.Size(275, 26)
        Me.tbDetail.TabIndex = 4
        '
        'tbDesc
        '
        Me.tbDesc.Location = New System.Drawing.Point(110, 131)
        Me.tbDesc.Name = "tbDesc"
        Me.tbDesc.ReadOnly = True
        Me.tbDesc.Size = New System.Drawing.Size(247, 26)
        Me.tbDesc.TabIndex = 186
        Me.tbDesc.TabStop = False
        '
        'tbNum
        '
        Me.tbNum.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbNum.Location = New System.Drawing.Point(9, 131)
        Me.tbNum.MaxLength = 4
        Me.tbNum.Name = "tbNum"
        Me.tbNum.Size = New System.Drawing.Size(58, 26)
        Me.tbNum.TabIndex = 2
        '
        'tbCrTotal
        '
        Me.tbCrTotal.BackColor = System.Drawing.Color.White
        Me.tbCrTotal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbCrTotal.Location = New System.Drawing.Point(879, 396)
        Me.tbCrTotal.Name = "tbCrTotal"
        Me.tbCrTotal.ReadOnly = True
        Me.tbCrTotal.Size = New System.Drawing.Size(92, 26)
        Me.tbCrTotal.TabIndex = 192
        Me.tbCrTotal.TabStop = False
        Me.tbCrTotal.Text = "0.000"
        Me.tbCrTotal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'tbDrTotal
        '
        Me.tbDrTotal.BackColor = System.Drawing.Color.White
        Me.tbDrTotal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbDrTotal.Location = New System.Drawing.Point(778, 396)
        Me.tbDrTotal.Name = "tbDrTotal"
        Me.tbDrTotal.ReadOnly = True
        Me.tbDrTotal.Size = New System.Drawing.Size(96, 26)
        Me.tbDrTotal.TabIndex = 191
        Me.tbDrTotal.TabStop = False
        Me.tbDrTotal.Text = "0.000"
        Me.tbDrTotal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.BackColor = System.Drawing.Color.Transparent
        Me.Label8.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label8.Location = New System.Drawing.Point(733, 375)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(38, 18)
        Me.Label8.TabIndex = 192
        Me.Label8.Text = "Total"
        '
        'tbTrxNo
        '
        Me.tbTrxNo.BackColor = System.Drawing.Color.White
        Me.tbTrxNo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbTrxNo.Location = New System.Drawing.Point(16, 61)
        Me.tbTrxNo.MaxLength = 10
        Me.tbTrxNo.Name = "tbTrxNo"
        Me.tbTrxNo.ReadOnly = True
        Me.tbTrxNo.Size = New System.Drawing.Size(124, 26)
        Me.tbTrxNo.TabIndex = 3
        Me.tbTrxNo.TabStop = False
        '
        'Label9
        '
        Me.Label9.AutoSize = True
        Me.Label9.BackColor = System.Drawing.Color.Transparent
        Me.Label9.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label9.Location = New System.Drawing.Point(13, 15)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(87, 18)
        Me.Label9.TabIndex = 195
        Me.Label9.Text = "Transaction #"
        '
        'Button3
        '
        Me.Button3.BackColor = System.Drawing.Color.Transparent
        Me.Button3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button3.Image = CType(resources.GetObject("Button3.Image"), System.Drawing.Image)
        Me.Button3.Location = New System.Drawing.Point(754, 62)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(42, 25)
        Me.Button3.TabIndex = 197
        Me.Button3.TabStop = False
        Me.Button3.UseVisualStyleBackColor = False
        '
        'tbTrx2
        '
        Me.tbTrx2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbTrx2.Location = New System.Drawing.Point(660, 63)
        Me.tbTrx2.MaxLength = 10
        Me.tbTrx2.Name = "tbTrx2"
        Me.tbTrx2.Size = New System.Drawing.Size(88, 26)
        Me.tbTrx2.TabIndex = 1
        Me.tbTrx2.TabStop = False
        '
        'Label10
        '
        Me.Label10.AutoSize = True
        Me.Label10.BackColor = System.Drawing.Color.Transparent
        Me.Label10.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label10.Location = New System.Drawing.Point(654, 18)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(177, 18)
        Me.Label10.TabIndex = 200
        Me.Label10.Text = "Transaction # to Copy/Paste"
        '
        'tbDiff
        '
        Me.tbDiff.BackColor = System.Drawing.Color.White
        Me.tbDiff.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tbDiff.Location = New System.Drawing.Point(827, 425)
        Me.tbDiff.Name = "tbDiff"
        Me.tbDiff.ReadOnly = True
        Me.tbDiff.Size = New System.Drawing.Size(107, 26)
        Me.tbDiff.TabIndex = 202
        Me.tbDiff.TabStop = False
        Me.tbDiff.Text = "0.000"
        Me.tbDiff.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'voucher_txt
        '
        Me.voucher_txt.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.voucher_txt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.voucher_txt.Location = New System.Drawing.Point(640, 131)
        Me.voucher_txt.Name = "voucher_txt"
        Me.voucher_txt.Size = New System.Drawing.Size(134, 26)
        Me.voucher_txt.TabIndex = 5
        '
        'Label11
        '
        Me.Label11.AutoSize = True
        Me.Label11.BackColor = System.Drawing.Color.Transparent
        Me.Label11.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label11.Location = New System.Drawing.Point(635, 85)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(84, 18)
        Me.Label11.TabIndex = 204
        Me.Label11.Text = "Voucher No."
        '
        'Label12
        '
        Me.Label12.AutoSize = True
        Me.Label12.BackColor = System.Drawing.Color.Transparent
        Me.Label12.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label12.Location = New System.Drawing.Point(279, 18)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(109, 18)
        Me.Label12.TabIndex = 195
        Me.Label12.Text = "Transaction Type"
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.cmdPost)
        Me.GroupPanel1.Controls.Add(Me.cmdPrint)
        Me.GroupPanel1.Controls.Add(Me.cmdSave)
        Me.GroupPanel1.Controls.Add(Me.cmdDelete)
        Me.GroupPanel1.Controls.Add(Me.cmdCut)
        Me.GroupPanel1.Controls.Add(Me.cmdOpen)
        Me.GroupPanel1.Controls.Add(Me.cmdNew)
        Me.GroupPanel1.Controls.Add(Me.cmdExit)
        Me.GroupPanel1.Controls.Add(Me.cmbDoc)
        Me.GroupPanel1.Controls.Add(Me.cmbChart)
        Me.GroupPanel1.Controls.Add(Me.Label10)
        Me.GroupPanel1.Controls.Add(Me.Label8)
        Me.GroupPanel1.Controls.Add(Me.Label12)
        Me.GroupPanel1.Controls.Add(Me.Label9)
        Me.GroupPanel1.Controls.Add(Me.Label11)
        Me.GroupPanel1.Controls.Add(Me.Label1)
        Me.GroupPanel1.Controls.Add(Me.Label2)
        Me.GroupPanel1.Controls.Add(Me.Label3)
        Me.GroupPanel1.Controls.Add(Me.Label4)
        Me.GroupPanel1.Controls.Add(Me.Label5)
        Me.GroupPanel1.Controls.Add(Me.Label6)
        Me.GroupPanel1.Controls.Add(Me.Label7)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(985, 520)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 205
        Me.GroupPanel1.Text = "GL Transactions - Add"
        '
        'cmdPost
        '
        Me.cmdPost.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPost.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPost.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPost.Location = New System.Drawing.Point(798, 455)
        Me.cmdPost.Name = "cmdPost"
        Me.cmdPost.Size = New System.Drawing.Size(82, 27)
        Me.cmdPost.TabIndex = 233
        Me.cmdPost.Text = "Post"
        '
        'cmdPrint
        '
        Me.cmdPrint.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPrint.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPrint.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPrint.Location = New System.Drawing.Point(710, 455)
        Me.cmdPrint.Name = "cmdPrint"
        Me.cmdPrint.Size = New System.Drawing.Size(82, 27)
        Me.cmdPrint.TabIndex = 233
        Me.cmdPrint.Text = "Print"
        '
        'cmdSave
        '
        Me.cmdSave.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdSave.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdSave.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdSave.Location = New System.Drawing.Point(622, 455)
        Me.cmdSave.Name = "cmdSave"
        Me.cmdSave.Size = New System.Drawing.Size(82, 27)
        Me.cmdSave.TabIndex = 233
        Me.cmdSave.Text = "Save"
        '
        'cmdDelete
        '
        Me.cmdDelete.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdDelete.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdDelete.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdDelete.Location = New System.Drawing.Point(534, 455)
        Me.cmdDelete.Name = "cmdDelete"
        Me.cmdDelete.Size = New System.Drawing.Size(82, 27)
        Me.cmdDelete.TabIndex = 233
        Me.cmdDelete.Text = "Delete"
        '
        'cmdCut
        '
        Me.cmdCut.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdCut.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdCut.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdCut.Location = New System.Drawing.Point(446, 455)
        Me.cmdCut.Name = "cmdCut"
        Me.cmdCut.Size = New System.Drawing.Size(82, 27)
        Me.cmdCut.TabIndex = 233
        Me.cmdCut.Text = "Cut"
        '
        'cmdOpen
        '
        Me.cmdOpen.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdOpen.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdOpen.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdOpen.Location = New System.Drawing.Point(358, 455)
        Me.cmdOpen.Name = "cmdOpen"
        Me.cmdOpen.Size = New System.Drawing.Size(82, 27)
        Me.cmdOpen.TabIndex = 233
        Me.cmdOpen.Text = "Open"
        '
        'cmdNew
        '
        Me.cmdNew.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdNew.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdNew.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdNew.Location = New System.Drawing.Point(270, 455)
        Me.cmdNew.Name = "cmdNew"
        Me.cmdNew.Size = New System.Drawing.Size(82, 27)
        Me.cmdNew.TabIndex = 233
        Me.cmdNew.Text = "New"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(886, 455)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 233
        Me.cmdExit.Text = "Exit"
        '
        'cmbChart
        '
        Me.cmbChart.DisplayMember = "Text"
        Me.cmbChart.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbChart.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbChart.ItemHeight = 19
        Me.cmbChart.Location = New System.Drawing.Point(104, 108)
        Me.cmbChart.Name = "cmbChart"
        Me.cmbChart.Size = New System.Drawing.Size(253, 25)
        Me.cmbChart.TabIndex = 205
        '
        'cmbDoc
        '
        Me.cmbDoc.DisplayMember = "Text"
        Me.cmbDoc.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbDoc.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbDoc.ItemHeight = 19
        Me.cmbDoc.Location = New System.Drawing.Point(282, 37)
        Me.cmbDoc.Name = "cmbDoc"
        Me.cmbDoc.Size = New System.Drawing.Size(214, 25)
        Me.cmbDoc.TabIndex = 205
        '
        'frmGLTransAdd
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(985, 520)
        Me.ControlBox = False
        Me.Controls.Add(Me.voucher_txt)
        Me.Controls.Add(Me.tbDiff)
        Me.Controls.Add(Me.tbTrx2)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.tbTrxNo)
        Me.Controls.Add(Me.tbDrTotal)
        Me.Controls.Add(Me.tbCrTotal)
        Me.Controls.Add(Me.tbCredit)
        Me.Controls.Add(Me.tbDpt)
        Me.Controls.Add(Me.tbDebit)
        Me.Controls.Add(Me.tbDetail)
        Me.Controls.Add(Me.tbNum)
        Me.Controls.Add(Me.DataGrid1)
        Me.Controls.Add(Me.tbRefer)
        Me.Controls.Add(Me.tbDate)
        Me.Controls.Add(Me.GroupPanel1)
        Me.Controls.Add(Me.tbDesc)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(30, 50)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmGLTransAdd"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub GLtransactionAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GVposTotal = 0
        'SavedID = 0
        PosCusName = ""
        PosCusID = 0
        RowUpdate = False


        tbDate.Text = Now.ToShortDateString
        Dim GLdata As New GLdataLogic
        Dim PosMode As DataSet
        Dim ds As DataSet
        ds = GLdata.GetDocumentTypes(CompanyID)
        cmbDoc.DataSource = ds.Tables(0)
        cmbDoc.ValueMember = "DOC_ID"
        cmbDoc.DisplayMember = "DOC_NAME"
        cmbDoc.SelectedValue = "JV"

        Dim ds2 As DataSet
        ds2 = GLdata.GetAllAccounts(0, 0)
        cmbChart.DataSource = ds2.Tables(0)
        cmbChart.ValueMember = "AccountID"
        cmbChart.DisplayMember = "AccountName"

        Dim InvoiceTable As DataTable = invoiceDS.Tables.Add("InvoiceLines")

        InvoiceTable.Columns.Add("AcNum", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("AcDpt", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("AcName", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("TrxDesc", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("Voucher", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("DrAmount", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("CrAmount", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("SlType", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("SlAcId", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("SlDocNum", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("SlDocType", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("SlDocRefer", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("SlDocFc", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("SlDocFcAmt", Type.GetType("System.String"))
        InvoiceTable.Columns.Add("Salesman", Type.GetType("System.String"))

        With DataGrid1
            .SetDataBinding(invoiceDS, "InvoiceLines")
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With
        Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
        Dim dv As DataView = cm.List
        dv.AllowNew = False

        'Set data grid Table Style
        Dim tblCrrncMngr As CurrencyManager = CType(BindingContext(invoiceDS.Tables.Item("InvoiceLines")), CurrencyManager)
        Dim TblStyle As New DataGridTableStyle
        With TblStyle
            .MappingName = "InvoiceLines"
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Calibri", 9.0!, FontStyle.Bold)
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
            .ReadOnly = True
            ' .RowHeaderWidth = 10

            ' Set column styles
            With .GridColumnStyles
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(0)
                    .MappingName = "AcNum"
                    .Width = tbNum.Width
                    .NullText = String.Empty
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(1)
                    .MappingName = "AcDpt"
                    .Width = tbDpt.Width
                    .NullText = String.Empty
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(2)
                    .MappingName = "AcName"
                    .Width = cmbChart.Width + 3
                    .NullText = String.Empty
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(3)
                    .MappingName = "TrxDesc"
                    .Width = tbDetail.Width + 5
                    .NullText = String.Empty
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(4)
                    .MappingName = "Voucher"
                    .Width = voucher_txt.Width + 3
                    .NullText = String.Empty
                    .Alignment = HorizontalAlignment.Left
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(5)
                    .MappingName = "DrAmount"
                    .Width = tbDebit.Width + 2
                    .NullText = String.Empty
                    .Alignment = HorizontalAlignment.Right
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))

                With .Item(6)
                    .MappingName = "CrAmount"
                    .Width = tbCredit.Width
                    .NullText = String.Empty
                    .Alignment = HorizontalAlignment.Right
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(7)
                    .MappingName = "SlType"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(8)
                    .MappingName = "SlAcID"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(9)
                    .MappingName = "SlDocNum"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(10)
                    .MappingName = "SlDocType"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(11)
                    .MappingName = "SlDocRefer"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(12)
                    .MappingName = "SlDocFc"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(13)
                    .MappingName = "SlDocFcAmt"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("InvoiceTable")))
                With .Item(14)
                    .MappingName = "Salesman"
                    .Width = 0
                    .NullText = String.Empty
                    .ReadOnly = True
                End With
            End With
        End With
        DataGrid1.TableStyles.Add(TblStyle)
        Dim GridItemCodeColumn As DataGridTextBoxColumn = DataGrid1.TableStyles(0).GridColumnStyles(0)
        cmbDoc.Focus()
    End Sub
    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click, cmdCut.Click
        Me.Hide()
    End Sub

    Private Function ValidateAccountCode() As Boolean
        ArAc = False
        ApAc = False
        FaAc = False
        EMAc = False

        Dim GLdata As New GLdataLogic
        If tbDpt.Text.Trim = "" Then
            tbDpt.Text = "000"
        End If

        If GLdata.ValidAccNumb(tbNum.Text.Trim) = False Then
            MsgBox("Invalid Account", MsgBoxStyle.Critical, "Inventory Manager")
            tbNum.Text = ""
            tbDpt.Text = ""
            tbNum.Focus()
            Return False
        ElseIf GLdata.ValidDpt(tbDpt.Text.Trim) = False Then
            Return False
            MsgBox("Invalid Account", MsgBoxStyle.Critical, "Inventory Manager")
            tbDpt.Text = ""
            tbDpt.Focus()
        Else
            Return True
        End If

        Try
            Dim ds As DataSet
            ds = GLdata.GetAccountDetails(CompanyID, tbNum.Text, tbDpt.Text)
            If ds.Tables(0).Rows.Count() = 0 Then
                GLdata = Nothing
                Return False
            End If

            tbDesc.Text = ds.Tables(0).Rows(0).Item("AccountName").ToString()
            cmbChart.SelectedValue = ds.Tables(0).Rows(0).Item("AccountID")
            Dim AType As String = ds.Tables(0).Rows(0).Item("AccountType").ToString()

            If AType = "CH" Or AType = "CA" Or AType = "CS" Or AType = "EX" Or AType = "FA" Then
                DebitOrCredit = 1
            End If
            If AType = "CL" Or AType = "FL" Or AType = "PN" Or AType = "SL" Or AType = "IN" Then
                DebitOrCredit = 2
            End If
            GLdata = Nothing

            If tbNum.Text = AR_Rec_AC Then
                ArAc = True
            Else
                ArAc = False
            End If

            If tbNum.Text = AP_Pay_AC Then
                ApAc = True
            Else
                ApAc = False
            End If

            If tbNum.Text = EMP_Cont_AC Then
                EMAc = True
            Else
                EMAc = False
            End If

            If tbNum.Text = FaAccount Then
                FaAc = True
            Else
                FaAc = False
            End If
            Return True

        Catch ex As Exception
            GLdata = Nothing
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "Inventory Manager")
            Return False
        End Try
    End Function
    Private Sub tbNum_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbNum.KeyUp
        If e.KeyCode = Keys.Enter Then
            If tbNum.Text <> "" Then
                SendKeys.Send("{Tab}")
            Else
                tbDpt.Focus()
            End If
        End If
    End Sub

    Private Sub tbDpt_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbDpt.KeyUp
        If e.KeyCode = Keys.Enter Then
            If tbDpt.Text = "" Then
                tbDpt.Text = "000"
            End If
            SendKeys.Send("{Tab}")
        End If
    End Sub
    Private Sub tbDetail_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbDetail.KeyUp
        If e.KeyCode = Keys.Enter Then
            If tbDetail.Text <> "" Then
                SendKeys.Send("{Tab}")
                'voucher_txt.Focus()
            End If
        End If
    End Sub
    Private Sub voucher_txt_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles voucher_txt.KeyUp
        If e.KeyCode = Keys.Enter Then
            If voucher_txt.Text <> "" Then
                SendKeys.Send("{Tab}")
                'voucher_txt.Focus()
            End If
        End If
    End Sub
    Private Sub tbDebit_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbDebit.KeyUp
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{Tab}")
        End If
    End Sub

    Private Sub tbCredit_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbCredit.KeyUp
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{Tab}")
        End If
    End Sub

    Private Sub InsertIntoGrid()
        If tbNum.Text.Trim <> "" And tbDpt.Text.Trim <> "" Then
            If tbDebit.Text.Trim <> "" Then
                If Not IsNumeric(tbDebit.Text) Then
                    MsgBox("Debit Amount should be numeric", MsgBoxStyle.Critical, "Inventory Manager")
                    tbDebit.Text = "0"
                    tbDebit.Focus()
                    Exit Sub
                End If
                If Decimal.Parse(tbDebit.Text) < 0 Then
                    MsgBox("Minus amount NOT allowed", MsgBoxStyle.Critical, "Inventory Manager")
                    tbDebit.Text = "0"
                    tbDebit.Focus()
                    Exit Sub
                End If
            End If
            If tbCredit.Text.Trim <> "" Then
                If Not IsNumeric(tbCredit.Text) Then
                    MsgBox("Credit Amount should be numeric", MsgBoxStyle.Critical, "Inventory Manager")
                    tbCredit.Text = "0"
                    tbCredit.Focus()
                    Exit Sub
                End If
                If Decimal.Parse(tbCredit.Text) < 0 Then
                    MsgBox("Minus amount NOT allowed", MsgBoxStyle.Critical, "Inventory Manager")
                    tbCredit.Text = "0"
                    tbCredit.Focus()
                    Exit Sub
                End If
            End If
            '
            If ArAc = True Then
                GlArAdd = New frmGLARTransAdd
                GlArAdd.ShowDialog()
            End If
            If ApAc = True Then
                GlApAdd = New frmGLAPTransAdd
                GlApAdd.ShowDialog()
            End If
            If FaAc = True Then

            End If
            '

            Dim ltot As Decimal
            Dim disp As Decimal
            Dim disa As Decimal
            Dim gtot As Decimal
            Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
            Dim dv As DataView = cm.List
            GridRows += 1
            'If GridRows > 8 Then 'And DataGrid1.Width <> 658
            '    DataGrid1.Width = 658
            'End If
            Dim mrow As Integer
            If RowUpdate = False Then
                dv.AllowNew = True
                dv.AddNew()
                mrow = dv.Table.Rows.Count
            Else
                mrow = DataGrid1.CurrentRowIndex
            End If
            DataGrid1.Item(mrow, 0) = tbNum.Text
            DataGrid1.Item(mrow, 1) = tbDpt.Text
            DataGrid1.Item(mrow, 2) = tbDesc.Text
            DataGrid1.Item(mrow, 3) = tbDetail.Text
            DataGrid1.Item(mrow, 4) = voucher_txt.Text
            If IsNumeric(tbDebit.Text) Then
                DataGrid1.Item(mrow, 5) = CDbl(tbDebit.Text).ToString("#0.000")
            Else
                DataGrid1.Item(mrow, 5) = ""
            End If
            If IsNumeric(tbCredit.Text) Then
                DataGrid1.Item(mrow, 6) = CDbl(tbCredit.Text).ToString("#0.000")
            Else
                DataGrid1.Item(mrow, 6) = ""
            End If
            '
            If ArAc = True Then
                DataGrid1.Item(mrow, 7) = "AR"
                DataGrid1.Item(mrow, 8) = GlArCusID
                DataGrid1.Item(mrow, 2) = GlArCusName
                DataGrid1.Item(mrow, 9) = GlArDocNum
                DataGrid1.Item(mrow, 10) = GlArDocType
                DataGrid1.Item(mrow, 11) = GlArDocRefer
                DataGrid1.Item(mrow, 14) = GlArSMan

            ElseIf EMAc = True Then
                DataGrid1.Item(mrow, 7) = "EM"
                DataGrid1.Item(mrow, 8) = GlEmpID
                DataGrid1.Item(mrow, 2) = GlEmpName
                DataGrid1.Item(mrow, 9) = GlEmpDocNum
                DataGrid1.Item(mrow, 10) = GlEmpDocType
                DataGrid1.Item(mrow, 11) = GlEmpDocRefer
                DataGrid1.Item(mrow, 14) = "9999"

            ElseIf ApAc = True Then
                DataGrid1.Item(mrow, 7) = "AP"
                DataGrid1.Item(mrow, 8) = GlApSupID
                DataGrid1.Item(mrow, 2) = GlApSupName
                DataGrid1.Item(mrow, 9) = GlApDocNum
                DataGrid1.Item(mrow, 10) = GlApDocType
                DataGrid1.Item(mrow, 11) = GlApDocRefer
                DataGrid1.Item(mrow, 12) = GlApFc
                DataGrid1.Item(mrow, 13) = GlApFcAmt
                DataGrid1.Item(mrow, 14) = "9999"
            Else
                DataGrid1.Item(mrow, 7) = ""
                DataGrid1.Item(mrow, 8) = ""
                DataGrid1.Item(mrow, 9) = ""
                DataGrid1.Item(mrow, 10) = ""
                DataGrid1.Item(mrow, 11) = ""
                DataGrid1.Item(mrow, 12) = ""
                DataGrid1.Item(mrow, 13) = ""
                DataGrid1.Item(mrow, 14) = "9999"
            End If

            dv.AllowNew = False
            tbNum.Clear()
            tbDpt.Clear()
            tbDesc.Clear()
            tbDetail.Clear()
            tbDebit.Clear()
            tbCredit.Clear()
            voucher_txt.Clear()

            GlArCusID = 0
            GlArDocNum = ""
            GlArDocType = ""
            GlArDocRefer = ""

            GlEmpID = 0
            GlEmpDocNum = ""
            GlEmpDocType = ""
            GlEmpDocRefer = ""

            GlApSupID = 0
            GlApDocNum = ""
            GlApDocType = ""
            GlApDocRefer = ""
            GlApFc = ""
            GlApFcAmt = ""

            If RowUpdate = True Then
                RowUpdate = False
                DataGrid1.Invalidate()
            End If
            CalcTotals()
        End If
        tbNum.Focus()
    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        If GridRows = 0 Then
            MsgBox("There is no entry to save.", MsgBoxStyle.Critical, "Inventory Manager")
            tbNum.Focus()
            Exit Sub
        End If
        Dim DrTot, CrTot As Double
        If IsNumeric(tbDrTotal.Text) Then
            DrTot = CDbl(tbDrTotal.Text)
        End If
        If IsNumeric(tbCrTotal.Text) Then
            CrTot = CDbl(tbCrTotal.Text)
        End If
        If DrTot <> CrTot Then
            MsgBox("Transaction should be balanced !", MsgBoxStyle.Critical, "Inventory Manager")
            Exit Sub
        End If
        Dim Response As String
        Response = InsertInvData("SAVE")
        tbTrxNo.Clear()
        tbTrx2.Clear()
        If Response <> "ERROR" Then
            MsgBox("Transaction No:" + Response + " Saved", MsgBoxStyle.Information, "Inventory Manager")
            ClearGridAndScreen()
            tbNum.Focus()
        Else
            MsgBox("Unable to SAVE this transaction." & vbLf + "Try again.", MsgBoxStyle.Critical, "Inventory Manager")
        End If
    End Sub
    Private Sub ClearGridAndScreen()
        Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
        Dim dv As DataView = cm.List
        Dim mrow, drow As Integer
        dv.RowStateFilter = DataViewRowState.Deleted
        drow = dv.Table.Rows.Count
        dv.RowStateFilter = DataViewRowState.CurrentRows
        mrow = dv.Table.Rows.Count
        Dim n As Integer
        For n = mrow To 0 Step -1
            Try
                dv.Delete(n)
            Catch ex As Exception
                Exit For
            End Try
        Next
        SavedID = 0
        tbNum.Clear()
        tbDesc.Clear()
        tbDpt.Clear()
        voucher_txt.Clear()
        tbDetail.Clear()
        tbDebit.Clear()
        tbCredit.Clear()
        tbDrTotal.Clear()
        tbCrTotal.Clear()
        tbDetail.Clear()
        tbRefer.Clear()
        tbTrxNo.Clear()
        tbDiff.Clear()
        tbNum.Focus()
        GridRows = 0
        GrossTotal = 0
        RowUpdate = False
        invoiceDS.Tables(0).Clear()
        DataGrid1.SetDataBinding(invoiceDS, "InvoiceLines")
        DataGrid1.Invalidate()
    End Sub
    Private Function InsertInvData(ByVal InvStatus As String) As String
        Try


            Dim InvXml As String
            Dim Response As String
            Dim GLdata As New GLdataLogic
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("<InvoiceDetails>")
            sb.Append("<InvoiceHead>")
            sb.Append("<TrxNum>" + tbTrxNo.Text + "</TrxNum>")
            sb.Append("<TrxDate>" + tbDate.Text + "</TrxDate>")
            sb.Append("<TrxSource>" + tbRefer.Text + "</TrxSource>")
            sb.Append("<TrxType>" + CStr(cmbDoc.SelectedValue) + "</TrxType>")
            sb.Append("</InvoiceHead>")
            '
            sb.Append("<InvoiceData>")
            Dim mrow, drow As Integer
            Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
            Dim dv As DataView = cm.List
            mrow = dv.Count
            Dim n As Integer
            For n = 0 To mrow - 1
                sb.Append("<InvLine>")
                sb.Append("<MainAccount>" + DataGrid1.Item(n, 0) + "</MainAccount>")
                sb.Append("<SubDpt>" + DataGrid1.Item(n, 1) + "</SubDpt>")
                sb.Append("<AcDesc>" + DataGrid1.Item(n, 2) + "</AcDesc>")
                sb.Append("<Voucher>" + DataGrid1.Item(n, 4) + "</Voucher>")
                sb.Append("<TrxRefer>" + DataGrid1.Item(n, 3) + "</TrxRefer>")
                sb.Append("<TrxDebit>" + DataGrid1.Item(n, 5) + "</TrxDebit>")
                sb.Append("<TrxCredit>" + DataGrid1.Item(n, 6) + "</TrxCredit>")
                sb.Append("<SubType>" + DataGrid1.Item(n, 7) + "</SubType>")
                sb.Append("<SubAcID>" + CStr(DataGrid1.Item(n, 8)) + "</SubAcID>")
                sb.Append("<SubDoc>" + DataGrid1.Item(n, 9) + "</SubDoc>")
                sb.Append("<SubTrxType>" + DataGrid1.Item(n, 10) + "</SubTrxType>")
                sb.Append("<SubRefer>" + DataGrid1.Item(n, 11) + "</SubRefer>")
                sb.Append("<SubFcCode>" + DataGrid1.Item(n, 12) + "</SubFcCode>")
                sb.Append("<SubFcAmt>" + DataGrid1.Item(n, 13) + "</SubFcAmt>")
                sb.Append("<Salesman>" + DataGrid1.Item(n, 14) + "</Salesman>")
                sb.Append("</InvLine>")
            Next
            sb.Append("</InvoiceData>")
            sb.Append("</InvoiceDetails>")
            InvXml = sb.ToString()
            Response = GLdata.ProcessGLtrxData(CompanyID, InvStatus, InvXml)
            Return Response
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Function

    Private Sub cmdCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCut.Click
        If MsgBox("Are you sure to delete this line?", MsgBoxStyle.YesNo, "Inventory Manager") = MsgBoxResult.Yes Then
            Try
                Dim CurrentRow As Integer = DataGrid1.CurrentCell.RowNumber
                DataGrid1.Select(CurrentRow)
                Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
                Dim dv As DataView = cm.List
                dv.Delete(CurrentRow)
                MsgBox("Deleted line data", MsgBoxStyle.Information, "Inventory Manager")
                CalcTotals()
            Catch ex As Exception
                MsgBox("Unable to delete", MsgBoxStyle.Exclamation, "Inventory Manager")
            End Try
            tbNum.Focus()
        Else
            'If MsgBox("Do you want to delete the this transaction?", MsgBoxStyle.YesNo, "Inventory Manager") = MsgBoxResult.Yes Then
            '    Try
            '        InsertInvData("DELETE")
            '        MsgBox("Transaction No:" & tbTrxNo.Text & " deleted", MsgBoxStyle.Information, "Inventory Manager")
            '        ClearGridAndScreen()
            '    Catch ex As Exception
            '        MsgBox("Unable to delete", MsgBoxStyle.Exclamation, "Inventory Manager")
            '    End Try
            '    tbNum.Focus()
            'End If
        End If
    End Sub

    Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 27) = True Then
            SearchTrxNumber = ""
            If icoSearch Is Nothing Then
                icoSearch = New frmGLJournalSearch
                icoSearch.ShowDialog()
            Else
                icoSearch.ShowDialog()
            End If
            If SearchTrxNumber <> "" Then
                ClearGridAndScreen()
                GridRows = 0
                PopulateSavedInvoice(SearchTrxNumber)
                tbTrxNo.Text = SearchTrxNumber
            End If
        Else
            MsgBox("Access Denied ", MsgBoxStyle.Critical, "Inventory Manager")
        End If


    End Sub
    Private Sub PopulateSavedInvoice(ByVal TrxNumber As String)
        Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
        Dim dv As DataView = cm.List
        Dim GLdata As New GLdataLogic
        Try
            Dim ds As DataSet
            ds = GLdata.GetJournalTrx(CompanyID, TrxNumber)
            If ds.Tables(0).Rows.Count() = 0 Then
                MsgBox("This is not a saved Journal Entry:" + vbLf + TrxNumber, MsgBoxStyle.Critical, "Inventory Manager")
                Exit Sub
            End If
            tbTrxNo.Text = ds.Tables(0).Rows(0).Item("TrxNumber")
            tbDate.Text = ds.Tables(0).Rows(0).Item("TrxDate")
            tbRefer.Text = ds.Tables(0).Rows(0).Item("TrxSource")
            cmbDoc.SelectedValue = tbTrxNo.Text.Substring(0, 2)
            dv.AllowNew = True
            Dim nrow As Integer
            Dim drow As DataRow
            For Each drow In ds.Tables(0).Rows
                dv.AddNew()
                DataGrid1.Item(nrow, 0) = drow("AcNum")
                DataGrid1.Item(nrow, 1) = drow("AcCent")
                DataGrid1.Item(nrow, 2) = drow("AcDesc")
                DataGrid1.Item(nrow, 3) = drow("TrxRefer")
                DataGrid1.Item(nrow, 4) = drow("Voucher")
                If IsNumeric(drow("TrxamtDr")) Then
                    If CDbl(drow("TrxAmtDr")) > 0 Then
                        DataGrid1.Item(nrow, 5) = CDbl(drow("TrxAmtDr")).ToString("#0.000")
                    Else
                        DataGrid1.Item(nrow, 5) = ""
                    End If
                Else
                    DataGrid1.Item(nrow, 6) = ""
                End If
                If IsNumeric(drow("TrxamtDr")) Then
                    If CDbl(drow("TrxAmtCr")) > 0 Then
                        DataGrid1.Item(nrow, 6) = CDbl(drow("TrxAmtCr")).ToString("#0.000")
                    Else
                        DataGrid1.Item(nrow, 6) = ""
                    End If
                Else
                    DataGrid1.Item(nrow, 6) = ""
                End If
                DataGrid1.Item(nrow, 7) = drow("SubArAp")
                DataGrid1.Item(nrow, 8) = drow("SubNum")
                DataGrid1.Item(nrow, 9) = drow("SubDoc")
                DataGrid1.Item(nrow, 10) = drow("SubType")
                DataGrid1.Item(nrow, 11) = drow("SubRefer")
                DataGrid1.Item(nrow, 12) = drow("SubFCode")
                DataGrid1.Item(nrow, 13) = drow("SubFc")
                DataGrid1.Item(nrow, 14) = drow("Salesman")
                nrow += 1
            Next
            GridRows = nrow
            CalcTotals()
        Catch ex As Exception
            MsgBox("Unable to satisfy your request." & vbLf & "Try again later.", MsgBoxStyle.Critical, "Inventory Manager")
        Finally
            GLdata = Nothing
        End Try
    End Sub

    Private Sub tbDate_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If tbDate.Text.Trim.Length <> 10 Then
            MsgBox("Date not in correct format," & vbLf & "Enter in dd/mm/yyyy format", MsgBoxStyle.Information, "Inventory Manager")
            tbDate.Focus()
        End If
    End Sub

    Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
        ClearGridAndScreen()
        GridRows = 0
    End Sub

    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        DataGrid1.Select(DataGrid1.CurrentRowIndex)
        If MsgBox("Do you wish to edit the selected row?", MsgBoxStyle.YesNo, "Inventory Manager") = MsgBoxResult.Yes Then
            Dim CurrentRow As Integer = DataGrid1.CurrentCell.RowNumber
            tbNum.Text = DataGrid1.Item(CurrentRow, 0)
            tbDpt.Text = DataGrid1.Item(CurrentRow, 1)
            tbDesc.Text = DataGrid1.Item(CurrentRow, 2)
            tbDetail.Text = DataGrid1.Item(CurrentRow, 3)
            voucher_txt.Text = DataGrid1.Item(CurrentRow, 4)
            tbDebit.Text = DataGrid1.Item(CurrentRow, 5)
            tbCredit.Text = DataGrid1.Item(CurrentRow, 6)
            '
            If ArAc = True Then
                GlArCusID = DataGrid1.Item(CurrentRow, 8)
                GlArDocNum = DataGrid1.Item(CurrentRow, 9)
                GlArDocType = DataGrid1.Item(CurrentRow, 10)
                GlArDocRefer = DataGrid1.Item(CurrentRow, 11)
            Else
                GlArCusID = 0
                GlArDocNum = ""
                GlArDocType = ""
                GlArDocRefer = ""
            End If

            If EMAc = True Then
                GlEmpID = DataGrid1.Item(CurrentRow, 8)
                GlEmpDocNum = DataGrid1.Item(CurrentRow, 9)
                GlEmpDocType = DataGrid1.Item(CurrentRow, 10)
                GlEmpDocRefer = DataGrid1.Item(CurrentRow, 11)
            Else
                GlEmpID = 0
                GlEmpDocNum = ""
                GlEmpDocType = ""
                GlEmpDocRefer = ""
            End If


            If ApAc = True Then
                GlApSupID = DataGrid1.Item(CurrentRow, 8)
                GlApDocNum = DataGrid1.Item(CurrentRow, 9)
                GlApDocType = DataGrid1.Item(CurrentRow, 10)
                GlApDocRefer = DataGrid1.Item(CurrentRow, 11)
                GlApFc = DataGrid1.Item(CurrentRow, 12)
                GlApFcAmt = DataGrid1.Item(CurrentRow, 13)
            Else
                GlApSupID = 0
                GlApDocNum = ""
                GlApDocType = ""
                GlApDocRefer = ""
                GlApFc = ""
                GlApFcAmt = ""
            End If
            '

            RowUpdate = True
            tbNum.Focus()
        Else
            RowUpdate = False
            DataGrid1.Invalidate()
        End If
    End Sub

    Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
        Dim pt As New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            DataGrid1.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            DataGrid1.Select(hti.Row)
        End If
    End Sub
    Private Sub tbDpt_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbDpt.Validated
        If tbDpt.Text.Trim = "" Then
            tbDpt.Text = "000"
        End If
        If tbNum.Text.Trim() <> "" And tbDpt.Text.Trim <> "" Then
            Dim GLdata As New GLdataLogic
            If GLdata.ValidDpt(tbDpt.Text) = False Then
                MsgBox("Invalid Department Code !", MsgBoxStyle.Critical, "Inventory Manager")
                tbDpt.Text = ""
                tbDpt.Focus()
            End If
        End If
    End Sub

    Private Sub tbDebit_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbDebit.Validated
        If IsNumeric(tbDebit.Text) Then
            If Decimal.Parse(tbDebit.Text) > 0 Then
                tbCredit.Text = ""
                InsertIntoGrid()
            Else
                tbDebit.Text = ""
                tbCredit.Focus()
            End If
        Else
            tbDebit.Text = ""
        End If
    End Sub

    Private Sub tbCredit_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbCredit.Validated
        If IsNumeric(tbCredit.Text) Then
            If Decimal.Parse(tbCredit.Text) > 0 Then
                tbDebit.Text = ""
                InsertIntoGrid()
            Else
                tbCredit.Text = ""
                tbDebit.Focus()
            End If
        Else
            tbCredit.Text = ""
        End If
    End Sub
    Private Sub voucher_txt_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles voucher_txt.LostFocus
        If DebitOrCredit = 1 Then
            tbDebit.Focus()
        Else
            tbCredit.Focus()
        End If
    End Sub
    'Private Sub tbDetail_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbDetail.LostFocus
    '    'If DebitOrCredit = 1 Then
    '    '    tbDebit.Focus()
    '    'Else
    '    '    tbCredit.Focus()
    '    'End If
    '    If e.KeyCode = Keys.Enter Then
    '        SendKeys.Send("{Tab}")
    '    End If
    'End Sub
    Private Sub CalcTotals()
        Dim mrow, drow As Integer
        Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
        Dim dv As DataView = cm.List
        mrow = dv.Count
        Dim n As Integer
        Dim dTot, cTot, cDif As Decimal
        dTot = 0
        cTot = 0
        cDif = 0
        For n = 0 To mrow - 1
            If IsNumeric(DataGrid1.Item(n, 5)) Then
                dTot += Decimal.Parse(DataGrid1.Item(n, 5))
            End If
            If IsNumeric(DataGrid1.Item(n, 6)) Then
                cTot += Decimal.Parse(DataGrid1.Item(n, 6))
            End If
        Next
        'anoop
        cDif = dTot - cTot
        tbDrTotal.Text = dTot.ToString("0.000")
        tbCrTotal.Text = cTot.ToString("0.000")
        tbDiff.Text = cDif.ToString("0.000")
    End Sub
    Private Sub cmbChart_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbChart.KeyUp, cmbDoc.KeyUp
        AutoCompleteCombo_KeyUp(cmbChart, e)
        If e.KeyCode = Keys.Enter Then
            SendKeys.Send("{Tab}")
        End If
    End Sub
    Private Sub cmbChart_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbChart.Leave, cmbDoc.Leave
        AutoCompleteCombo_Leave(cmbChart)
    End Sub
    Private Sub cmbChart_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbChart.Validated, cmbDoc.Validated
        If IsNumeric(cmbChart.SelectedValue) Then
            Dim AcID As Integer
            AcID = cmbChart.SelectedValue
            Dim GLdata As New GLdataLogic
            Dim ds3 As DataSet
            ds3 = GLdata.GetAccountDetailsByAccountID(AcID)
            tbNum.Text = ds3.Tables(0).Rows(0).Item("AccountNumber")
            tbDpt.Text = ds3.Tables(0).Rows(0).Item("AccountCenter")
            GLdata = Nothing
            tbDetail.Focus()
        End If
    End Sub

    Private Sub cmdPost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPost.Click
        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, 1, 28) = True Then
            SearchTrxNumber = ""
            If icoPost Is Nothing Then
                icoPost = New frmGLJournalPost
                icoPost.ShowDialog()
            Else
                icoPost.ShowDialog()
            End If
            ClearGridAndScreen()
            GridRows = 0
        Else
            MsgBox("Access Denied !", MsgBoxStyle.Critical, "Inventory Manager")
        End If
        ApData = Nothing
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If tbTrx2.Text <> "" Then
            ClearGridAndScreen()
            GridRows = 0
            PopulateSavedInvoice(tbTrx2.Text)
            tbTrxNo.Text = ""
        End If
    End Sub

    Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
        If DelGlTran = True Then
            If tbTrxNo.Text <> "" Then
                If (MsgBox("Do you wish to delete this transaction batch?" & vbLf & "Trx.No:" & tbTrxNo.Text, MsgBoxStyle.YesNo, "Inventory Manager") = MsgBoxResult.Yes) Then
                    Dim GLdata As New GLdataLogic
                    Dim resp As String
                    resp = GLdata.DeleteGJtrxData(CompanyID, tbTrxNo.Text)
                    If resp = "OK" Then
                        MsgBox("Transaction Batch No:" & tbTrxNo.Text & " deleted", MsgBoxStyle.Information, "Inventory Manager")
                        ClearGridAndScreen()
                        tbTrxNo.Text = ""
                    Else
                        MsgBox("Unable to delete Transaction Batch No:" & tbTrxNo.Text & ". Try Later", MsgBoxStyle.Critical, "Inventory Manager")
                    End If
                End If
            Else
                MsgBox("Only saved Transaction Batch can be deleted!", MsgBoxStyle.Information, "Inventory Manager")
            End If
        Else
            MsgBox("Access Denied!", MsgBoxStyle.Information, "Inventory Manager")
        End If
    End Sub

    Private Sub cmdPrintPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        Dim ds As DataSet = New DataSet("SerpsRpt")
        Dim table As DataTable = New DataTable("SerpsRpt")
        table.Columns.Add("Str1")
        table.Columns.Add("Str2")
        table.Columns.Add("Str3")
        table.Columns.Add("Str4")
        table.Columns.Add("Str5")
        table.Columns.Add("Dec1")
        table.Columns.Add("Dec2")
        Dim mrow, drow As Integer
        Dim cm As CurrencyManager = BindingContext(DataGrid1.DataSource, DataGrid1.DataMember)
        Dim dv As DataView = cm.List
        dv.RowStateFilter = DataViewRowState.CurrentRows
        mrow = dv.Count
        'mrow = mrow - drow
        Dim ProdCode As String
        Dim ProdDesc As String
        Dim ProdQty As String

        Dim n As Integer
        For n = 0 To mrow - 1
            Dim nrow As DataRow = table.NewRow()
            nrow("Str1") = DataGrid1.Item(n, 0)
            nrow("Str2") = DataGrid1.Item(n, 1)
            nrow("Str3") = DataGrid1.Item(n, 2)
            nrow("Str4") = DataGrid1.Item(n, 3)
            nrow("Str5") = DataGrid1.Item(n, 4)
            nrow("Dec1") = DataGrid1.Item(n, 5)
            nrow("Dec2") = DataGrid1.Item(n, 6)
            table.Rows.Add(nrow)
        Next
        ds.Tables.Add(table)
        Dim Dr, Cr As Double
        Dr = CDbl(tbDrTotal.Text).ToString("#0.000")
        Cr = CDbl(tbCrTotal.Text).ToString("#0.000")
        gLtransactionEditList1.Load()
        gLtransactionEditList1.SetDataSource(ds)

        gLtransactionEditList1.SetParameterValue("CompanyName", " SAFARI HOUSE GENERAL TRADING COMPANY W.L.L ")
        gLtransactionEditList1.SetParameterValue("ReportTitle", "Ledger Transaction Edit List")
        gLtransactionEditList1.SetParameterValue("TrxDoc", cmbDoc.Text)
        gLtransactionEditList1.SetParameterValue("TrxDate", tbDate.Text)
        gLtransactionEditList1.SetParameterValue("TrxSource", tbRefer.Text)
        gLtransactionEditList1.SetParameterValue("TrxNumber", tbTrxNo.Text)
        gLtransactionEditList1.SetParameterValue("Dr", tbDrTotal.Text)
        gLtransactionEditList1.SetParameterValue("Cr", tbCrTotal.Text)
        gLtransactionEditList1.SetParameterValue("un", UserName)

        If PrntPrv Is Nothing Then
            PrntPrv = New PrintPreviewForm
            PrntPrv.CrRptView.ReportSource = gLtransactionEditList1
            PrntPrv.ShowDialog()
        End If
        gLtransactionEditList1.Close()
        'GLtransactionEditList1.PrintOptions.PrinterName = InvoicePrinter
        'Try
        '    GLtransactionEditList1.PrintToPrinter(1, True, 0, 0)
        'Catch ex As Exception
        '    MsgBox(ex.ToString)
        'End Try
    End Sub




    Private Sub cmbDoc_SelectedIndexChanged(sender As System.Object, e As System.EventArgs)

    End Sub
End Class
